package managedbean; 
 
import entity.SaleLead.CustomerType;
import java.io.Serializable;
import javax.ejb.EJB; 
import javax.enterprise.context.RequestScoped;
import javax.faces.application.FacesMessage; 
import javax.faces.bean.ManagedBean; 
import javax.faces.context.FacesContext; 
import javax.faces.event.ActionEvent; 
import session.stateless.SaleLeadBeanLocal;
 
@ManagedBean(name="saleLeadManagerBean")
@RequestScoped
public class SaleLeadManagerBean implements Serializable { 
    @EJB 
    private SaleLeadBeanLocal saleLeadBeanLocal; 
     
    private String saleLeadName; 
    private String NRIC;
    private String email;
    private String address;
    private String contactNumber;
    private CustomerType customerType;
    private Long saleLeadId;
    private String statusMessage;
 
    public String getSaleLeadName() { 
        return saleLeadName; 
    } 
    
    public void setSaleLeadName(String saleLeadName) { 
        this.saleLeadName = saleLeadName; 
    }

    public String getNRIC() {
        return NRIC;
    }
    public void setNRIC(String NRIC) {
        this.NRIC = NRIC;
    }

    public String getEmail() {
        return email;
    }
    public void setEmail(String email) {
        this.email = email;
    }
    
    public String getAddress() {
        return address;
    }
    public void setAddress(String address) {
        this.address = address;
    }

    public String getContactNumber() {
        return contactNumber;
    }
    public void setContactNumber(String contactNumber) {
        this.contactNumber = contactNumber;
    }

    public CustomerType getCustomerType() {
        return customerType;
    }
    public void setCustomerType(CustomerType customerType) {
        this.customerType = customerType;
    }
    
    public String getStatusMessage() { 
        return statusMessage; 
    } 
    public void setStatusMessage(String statusMessage) { 
        this.statusMessage = statusMessage; 
    }

    public Long getSaleLeadId() {
        return saleLeadId;
    }
    public void setSaleLeadId(Long saleLeadId) {
        this.saleLeadId = saleLeadId;
    }
    
    public void saveNewSaleLead(ActionEvent event) 
    { 
        String temp_Name = String.valueOf(saleLeadName);
        String temp_NRIC = String.valueOf(NRIC);
        String temp_email = String.valueOf(email);
        String temp_address = String.valueOf(address);
        String temp_contactNumber = String.valueOf(contactNumber);
        CustomerType temp_CustomerType = customerType;
                
        try 
        { 
            saleLeadId = saleLeadBeanLocal.createSaleLead(temp_Name,temp_NRIC, temp_email, temp_address, temp_contactNumber, temp_CustomerType);

            statusMessage = "New saleLead Saved Successfully"; 
 
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO,  "Add New Sale Lead Result: " +statusMessage + " (New saleLead ID is " + saleLeadId.toString() + ")", "")); 
        } 
        catch(Exception ex) 
        { 
            ex.printStackTrace(); 
        } 
    }    
    
    public void updateExistingSaleLead(ActionEvent event) 
    { 
        Long temp_id = Long.valueOf(saleLeadId);
        String temp_Name = String.valueOf(saleLeadName);
        String temp_NRIC = String.valueOf(NRIC);
        String temp_email = String.valueOf(email);
        String temp_address = String.valueOf(address);
        String temp_contactNumber = String.valueOf(contactNumber);
        CustomerType temp_customerType = customerType;
                
        try 
        { 
            saleLeadBeanLocal.updateSaleLead(temp_id, temp_Name, temp_NRIC, temp_email, temp_address, temp_contactNumber, temp_customerType);
            statusMessage = "Existing Sale Lead Updated Successfully"; 
 
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO,  "Add New Sale Lead Result: " +statusMessage + " (Existing saleLead ID is " + saleLeadId + ")", "")); 
        } 
        catch(Exception ex) 
        { 
            ex.printStackTrace(); 
        } 
    }    
    public String refresh_name(long saleLeadId){
        return saleLeadBeanLocal.find(saleLeadId).getSaleLeadName();
    }
    public String refresh_NRIC(long saleLeadId){return saleLeadBeanLocal.find(saleLeadId).getSaleLeadNRIC();}
    public String refresh_email(long saleLeadId) {return saleLeadBeanLocal.find(saleLeadId).getSaleLeadEmail();}
    public String refresh_contactNumber(long saleLeadId){return saleLeadBeanLocal.find(saleLeadId).getSaleLeadContactNumber();}
    public String refresh_address(long saleLeadId){return saleLeadBeanLocal.find(saleLeadId).getSaleLeadAddress();}
    public CustomerType refresh_customerType(long saleLeadId){return saleLeadBeanLocal.find(saleLeadId).getCustomerType();}    
}
    

